#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int i,n,sum1,sum2,num1,num2,score,cla;
	while (cin >> n)
	{
		num1 = num2 = sum1=sum2=0;
		while (n--)
		{
			cin >> score >> cla;
			if (cla == 1)
			{
				sum1 += score;
				num1++;
			}
			else
			{
				sum2 += score;
				num2++;
			}
		}
		cout << sum1 / num1 << " " << sum2 / num2 << "\r\n";



	}
	return 0;
}